#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'in.bam'
exit 1
}

while getopts  ":p:f:i:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
        i) interval=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

:<<mark
$java_run/picard/CollectInsertSizeMetrics.jar \
I=$1 \
O=$out_prefix.insert_size \
H=$out_prefix.insert_size.hist

insert_size=`grep MEDIAN_INSERT_SIZE $out_prefix.insert_size -A1|tail -1|cut -f1`


echo -e "$1\t$insert_size\t$sample_name" > $out_prefix.pindel.config

echo pindel run
pindel -f $ref_genome \
-i $out_prefix.pindel.config \
-c ALL -T 4 -o $out_prefix

pindel2vcf -r $ref_genome \
-R REF_NAME \
-P $out_prefix -v $out_prefix.pindel.vcf


echo varscan run
samtools view -H $1|grep '^@RG'|sed 's/\tSM:/ /'|cut -f2 -d' '|cut -f1 > $out_prefix.sample_names
# echo $sample_name > $out_prefix.sample_names
samtools mpileup -f $ref_genome $1 |
$java_run/varscan mpileup2indel \
-d 20120203 \
–output-vcf 1 \
–vcf-sample-list $out_prefix.sample_names.list \
> $out_prefix.varscan.vcf

mark

echo bcftools run
samtools mpileup -t DP -t SP  -ugf $ref_genome \
$1 |
bcftools view -Ncvg –
> $out_prefix.bcf.vcf

. $cmd_done